package com.example.springbootvuetest.service.impl;

import com.example.springbootvuetest.entity.Admin;
import com.example.springbootvuetest.entity.IdleItem;
import com.example.springbootvuetest.entity.Order;
import com.example.springbootvuetest.entity.dto.TableDto;
import com.example.springbootvuetest.mapper.AdminMapper;
import com.example.springbootvuetest.mapper.IdleItemMapper;
import com.example.springbootvuetest.mapper.OrderMapper;
import com.example.springbootvuetest.service.IAdminService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.springbootvuetest.service.IIdleItemService;
import com.example.springbootvuetest.service.IOrderService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author shuoye
 * @since 2023-03-14
 */
@Service
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements IAdminService {
    private final IdleItemMapper idleItemMapper;
    private final OrderMapper orderMapper;

    @Override
    public List<TableDto> getTableOrder() {
        List<TableDto> list = orderMapper.getMouthData();
        if (list.size() > 0) {
            List<Integer> idleIdList = new ArrayList<>();
            for (TableDto i : list) {
                idleIdList.add(i.getIdleId());
            }
            List<IdleItem> idleItems = idleItemMapper.selectBatchIds(idleIdList);
            Map<Integer, IdleItem> map = new HashMap<>();
            for (IdleItem idle : idleItems) {
                map.put(idle.getId(), idle);
            }
            for (TableDto o : list) {
                System.out.println(o);
                o.setIdleName(map.get(o.getIdleId()).getIdleName());
                o.setDayTrade(orderMapper.getDayData(o.getIdleId()));
                o.setSumTrade(orderMapper.getSumData(o.getIdleId()));
            }
        }
        return list;
    }
}
